package com.example.chessbattleplatform.web.StorageIo.CopyUtils;

import com.example.chessbattleplatform.web.StorageIo.Pojo.Mapper.FileStorage;
import com.example.chessbattleplatform.web.StorageIo.Pojo.Vo.UploadFileVo;
import org.mapstruct.Mapper;

import javax.activation.MimetypesFileTypeMap;

@Mapper(componentModel = "spring")
public abstract class CopyFileUtils {
    private String getShowUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/fileApi/show/" + uuid;
    }

    private String getDownloadUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/fileApi/download/" + uuid;
    }

    private String getDeleteUuid(String uuid) {
        // 要保证 controller 的 showFile 方法是这个 'show/' 请求
        return "/fileApi/delete/" + uuid;
    }

    public UploadFileVo FileStorageToUploadFileVo(FileStorage fileService) {
        String fileId = fileService.getFileId();
        return UploadFileVo.builder()
                .fileID(fileId)
                .fileName(fileService.getName())
                .url(getShowUuid(fileId))
                .downloadUrl(getDownloadUuid(fileId))
                .deleteUrl(getDeleteUuid(fileId))
                .type(new MimetypesFileTypeMap().getContentType(fileService.getName()))
                .build();
    }

}
